import { HttpClient } from '@angular/common/http';
import { ArrayType } from '@angular/compiler';
import { Component, OnInit } from '@angular/core';
import { DialogService } from 'ngx-metro';
import { AddArticleDto } from '../dto/add-article-dto';

@Component({
    selector: 'app-rich-text',
    templateUrl: './rich-text.component.html',
    styleUrls: ['./rich-text.component.scss'],
    standalone: false
})
export class RichTextComponent implements OnInit {
  content: any;
  html = '';
  title = '';
  articleType = 1;

  constructor(private http: HttpClient, private dialogService: DialogService) {}

  ngOnInit(): void {}

  onContentChanged() {
    console.log(this.content);
    console.log(this.html);
  }

  commitArticle(publishType: number) {
    this.http
      .post('/article/addArticle', {
        articleHtml: this.html,
        articleTitle: this.title,
        articleType: this.articleType,
        publishType: publishType,
      })
      .subscribe((data: any) => {
        if(data.success){
          this.dialogService.info("添加文章"+data.message);
          this.html = '';
          this.title = '';
          this.content = '';
        }

      });
  }
}
